package cn.jtool.dig.server.dao.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "port_mapping")
public class PortMapping implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String portMappingName;

    private String sourceIp;

    private Integer sourcePort;

    private Integer licenseId;

    private String licenseKey;

    private String targetIp;

    private Integer targetPort;

    private Integer enableState;

    private String whiteIps;

    private String blackIps;

    private String notes;

    private Date createTime;

    private Date updateTime;

    public void addWhiteIps(String ip){
        if(StringUtils.isNotBlank(this.whiteIps)){
            this.whiteIps += ",";
        }
        this.whiteIps += ip;
    }
    public void addBlackIps(String ip){
        if(StringUtils.isNotBlank(this.blackIps)){
            this.blackIps += ",";
        }
        this.blackIps += ip;
    }
}
